package com.freecloud.spring.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;

import java.beans.PropertyDescriptor;

/**
 * @Author: maomao
 * @Date: 2021-04-19 14:21
 */
public class MyInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {

    public MyInstantiationAwareBeanPostProcessor(){
        super();
        System.out.println("【构造方法】MyInstantiationAwareBeanPostProcessor！！");
    }

    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        System.out.println("【MyInstantiationAwareBeanPostProcessor接口】postProcessBeforeInstantiation。" + beanName);
        return super.postProcessBeforeInstantiation(beanClass, beanName);
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        System.out.println("【MyInstantiationAwareBeanPostProcessor接口】postProcessAfterInstantiation。" + beanName);
        return super.postProcessAfterInstantiation(bean, beanName);
    }

    @Override
    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
        System.out.println("【MyInstantiationAwareBeanPostProcessor接口】postProcessPropertyValues。" + beanName);
        return super.postProcessPropertyValues(pvs, pds, bean, beanName);
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("【MyInstantiationAwareBeanPostProcessor接口】postProcessBeforeInitialization。" + beanName);
        return super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("【MyInstantiationAwareBeanPostProcessor接口】postProcessAfterInitialization。" + beanName);
        return super.postProcessAfterInitialization(bean, beanName);
    }
}
